% Script to get the time series processed as averages of the past values.
% 

function[X] = cascade_average(ts)

N = 20;
A = cumsum(N);

if length(ts) < A(end),
    X = NaN;
    return;
end;


icount = 1;

nsegments = length(ts)-A(end);
start_index = A(end);


for j = 1:nsegments

increment = 0;    
    
for i = 1:N,
    
    X(j,i) = mean(ts(start_index - increment:start_index));
    
    increment = increment + 1;
    start_index = start_index - increment;
    
end;
end;